package com.wb.controller;

import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.wb.bean.User;
import com.wb.bean.test.TestObject;
import com.wb.service.IPropertiesConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
public class UserController {

    private final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Resource(name = "propertiesConfiguration")
    private IPropertiesConfiguration iPropertiesConfiguration;

    @Resource(name="fastJsonConfig")
    private FastJsonConfig fastJsonConfig;

    @RequestMapping(value="getUser")
    public User getUser() {
        User user = iPropertiesConfiguration.printObject();
        logger.info("user: {} " , user);
        return user;
    }

    @RequestMapping(value="setUser")
    public User setUser(User user) {
        logger.info("setUser: {} " , user);
        return user;
    }

    @RequestMapping(value="getTestObject",method = RequestMethod.GET , produces = "application/json;charset=UTF-8")
    public TestObject getTestObject() {
        TestObject testObject = new TestObject("hahahaha",10);
        logger.info("testObject: {} charset: {} " , testObject , fastJsonConfig.getCharset());
        return testObject;
    }

    @RequestMapping(value="postTestObject",method= RequestMethod.POST)
    public TestObject postTestObject() {
        TestObject testObject = new TestObject("test",10);
        logger.info("testObject: {} charset: {} " , testObject , fastJsonConfig.getCharset());
        return testObject;
    }

    @RequestMapping(value="getMap",method= RequestMethod.GET)
    public Map<String,Object> getMap() {
        Map<String,Object> paramsMap = new HashMap<String,Object>();
        paramsMap.put("username","adafssf");
        paramsMap.put("asdfaf","asdfasf");
        return paramsMap;
    }

    @RequestMapping(value="getMapByPost",method= RequestMethod.POST)
    public Map<String,Object> getMapByPost() {
        Map<String,Object> paramsMap = new HashMap<String,Object>();
        paramsMap.put("username","adafssf");
        paramsMap.put("asdfaf","asdfasf");
        return paramsMap;
    }

}
